#!/bin/bash

#----------------------------------------------------
# File: arg.sh
# Contents: 函数参数
# Date: 18-11-11
#----------------------------------------------------

#---------------------------------------------------------------------------------------------------
# $ 的特殊用法:
#
# $@ 参数数组
# $* 参数数组
#
# $# 参数长度
#
# $$ 返回当前进程的pid
#
# $? 上一个命令或者函数的返回值
#
# $0 命令本身
# $n 第n个参数, n>0
#---------------------------------------------------------------------------------------------------

param() {
    echo "参数数组: $*"
    echo "参数数组: $@"
    echo "参数个数: $#"
    echo

    echo "======================================"
    echo "参数遍历*"
    for i in "$*"
    do
        echo ${i}
    done
    echo

    echo "======================================"
    echo "参数遍历@"
    for i in "$@"
    do
        echo ${i}
    done
    echo

    echo "参数命令: $0"
    echo "当前进程pid: $$"
    echo "上一条命令返回值: $?"
}

param "AA" "BB"